-
-
Notifications
You must be signed in to change notification settings - Fork 195
[hi-rachel] Week 8 solutions #1503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제마다 접근한 방법, 시간/공간 복잡도, 코멘트가 잘 정리되어 있어 코드를 더 잘 이해할 수 있었던 것 같아요! 이번 주도 고생 많으셨습니다~ 새로운 한 주도 화이팅! 💪🏻
그래프의 깊은 복사 반환해라 | ||
|
||
TC: O(V + E), V: 노드의 수, E: 이웃의 수 | ||
SC: O(V + E) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드가 매우 직관적이고 알아보기 쉽게 작성된 것 같아요 🤩
다만 clones
에는 노드의 개수만큼 복제 노드가 저장되고, DFS의 경우 call stack이 최대 노드의 개수만큼, BFS의 경우 queue
가 최대 노드의 개수만큼 커질 것이기 때문에 공간 복잡도는 O(V) 가 될 것 같습니다..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seungriyou 복제된 그래프의 전체 구조까지 포함한 공간을 고려하면
O(V + E)가 될 수 있을 것 같습니다!
if text1[i - 1] == text2[j - 1]: | ||
dp[i][j] = dp[i - 1][j - 1] + 1 # 두 문자가 같으면, 이전 상태 + 1 | ||
else: | ||
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) # 다르면, 하나 줄인 상태 중 최댓값 선택 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저 또한 rachel 님처럼 처음에 2D DP(O(m * n)
space)로 접근했었는데요, 2D DP에서 매 단계마다 dp[i - 1]
row와 dp[i]
row만 확인하기 때문에 이를 1D DP(O(n)
space)로 공간 복잡도를 최적화 할 수 있다는 점을 알게 되어 공유드립니다!
dp[i - 1]
row와 dp[i]
row를 각각 길이가 n + 1
인 리스트인 prev
와 curr
로 두고, 이를 모든 row 마다 번갈아 가며 사용하면 최적화가 가능하다고 해요~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seungriyou 좋은 리뷰 감사합니다. 다시 풀때 최적화 해보도록 하겠습니다!
항상 32비트이므로 상수 시간, 상수 공간 | ||
TC: O(1) | ||
SC: O(1) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여러 방법으로 풀이해주셔서 많은 참고가 되었습니다! 😆
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!